<template>
  <div class="qa-list-container">
    <!-- 搜索区域 -->
    <div class="search-section">
      <el-input
        v-model="searchValue"
        placeholder="搜索农业问题"
        clearable
        class="search-input"
        @keyup.enter.native="handleSearch">
        <el-button
          slot="append"
          icon="el-icon-search"
          @click="handleSearch">
        </el-button>
      </el-input>
      
      <div class="hot-search-tags">
        <span class="hot-title">热门搜索：</span>
        <el-tag
          v-for="(tag, index) in hotTags"
          :key="index"
          class="hot-tag"
          @click="handleTopicDetail(tag)">
          {{ tag }}
        </el-tag>
      </div>
    </div>

    <!-- 问答列表 -->
    <div class="qa-list">
      <el-card
        v-for="(item, index) in cgoods"
        :key="index"
        class="qa-card"
        shadow="hover"
        @click.native="handleDetail(item)">
        
        <div class="qa-header">
          <el-tag
            :type="item.status === 0 ? 'info' : 'success'"
            size="small">
            {{ item.status === 0 ? '问' : '答' }}
          </el-tag>
          <h4 class="qa-title">{{ item.title }}</h4>
        </div>
        
        <div class="qa-meta">
          <div class="qa-participants">
            <span><i class="el-icon-user"></i> 提问者：{{ item.questioner }}</span>
            <span><i class="el-icon-s-custom"></i> 专家：{{ item.expertName || '待解答' }}</span>
          </div>
        </div>
      </el-card>
    </div>

    <!-- 分页 -->
    <div class="pagination-section">
      <el-pagination
        @current-change="pageClick"
        :current-page.sync="currentPage"
        :page-size="pageSize"
        :total="total"
        layout="prev, pager, next, jumper"
        background>
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      searchValue: '',
      hotTags: [
        '苹果果树种植方法',
        '新疆哈密瓜甜度控制',
        '玉米苗灌溉'
      ],
      currentPage: 1
    };
  },
  props: {
    cgoods: {
      type: Array,
      required: true
    },
    total: {
      type: Number,
      required: true
    },
    pageSize: {
      type: Number,
      required: true
    },
    url: {
      type: String,
      required: true
    }
  },
  methods: {
    pageClick(val) {
      this.$emit('pageClick', val);
    },
    handleSearch() {
      this.$emit('handleSearch', this.searchValue);
    },
    handleDetail(item) {
      this.$router.push(`/home/guide/${item.id}`);
    },
    handleTopicDetail(val) {
      this.searchValue = val;
      this.handleSearch();
    }
  },
  mounted() {
    this.$store.commit("updateActiveIndex", "5");
  }
};
</script>

<style lang="less" scoped>
.qa-list-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
  
  .search-section {
    margin-bottom: 20px;
    
    .search-input {
      width: 100%;
      margin-bottom: 15px;
      
      /deep/ .el-input-group__append {
        background-color: #67C23A;
        color: white;
        border-color: #67C23A;
      }
    }
    
    .hot-search-tags {
      .hot-title {
        color: #909399;
        font-size: 14px;
        margin-right: 10px;
      }
      
      .hot-tag {
        margin-right: 10px;
        cursor: pointer;
        background-color: #f0f9eb;
        color: #67C23A;
        border-color: #e1f3d8;
        
        &:hover {
          background-color: #e1f3d8;
        }
      }
    }
  }
  
  .qa-list {
    margin-bottom: 20px;
  }
  
  .qa-card {
    margin-bottom: 15px;
    cursor: pointer;
    transition: all 0.3s;
    
    &:hover {
      transform: translateY(-3px);
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }
    
    .qa-header {
      display: flex;
      align-items: center;
      margin-bottom: 10px;
      
      .qa-title {
        margin: 0 0 0 10px;
        font-size: 16px;
        color: #303133;
        flex: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
    
    .qa-meta {
      .qa-participants {
        display: flex;
        justify-content: space-between;
        font-size: 13px;
        color: #909399;
        
        span {
          margin-right: 15px;
          
          i {
            margin-right: 5px;
          }
        }
      }
    }
  }
  
  .pagination-section {
    text-align: center;
    margin-top: 20px;
  }
}
</style>